import { uploadFileManagerListJson,setFileName,removeFile} from '@/services/AdminFile';
import {setRefault} from '@/utils/Base';
import { message } from 'antd';
const AdminFileModel = {
  namespace: 'AdminFile',
  state: {
    FileList:{//集体数据
      list:[]
    },
    refault:{},
  },
  effects: {
    *uploadFileManagerListJson({ payload,callback }, { call, put }) {
      const response = yield call(uploadFileManagerListJson,payload);
      yield put({
        type: 'saveSelect',
        payload: response,
      });
      setRefault(response);
      (callback && typeof(callback) === "function") && callback(response);
    },
    *setFileName({ payload,callback }, { call, put }) {
        //console.log('params',payload);
      const response = yield call(insert,payload);
      yield put({
        type: 'saveUpdate',
        payload: response,
      });
      setRefault(response);
      (callback && typeof(callback) === "function") && callback(response);
    },
    *removeFile({ payload,callback }, { call, put }) {
      //console.log('params',payload);
      const response = yield call(removeFile,payload);
      yield put({
        type: 'saveRemove',
        payload: response,
      });
      setRefault(response);
      (callback && typeof(callback) === "function") && callback(response);
    },
  },
  reducers: {
    saveSelect(state, action) {
      var data = {};
      if(action.payload.code === 1){
          data = action.payload.data;
      }else{
          message.error(action.payload.msg);
      }
      return {
        ...state,
        FileList: data,//这个地方回调执行更新数据格式一个大坑 必须写data才可以
      };
    },
    saveRemove( state , {payload} ){
      if(payload.code === 1){
            message.success(payload.msg);
        }
      return { ...state,refault:payload};
    },
    saveUpdate(state,action){
        if(action.payload.code === 1){
            message.success(action.payload.msg);
        }else{
            message.error(action.payload.msg);
        }
        return { ...state,refault:action.payload};
    },
    changeNotifyCount(
      state = {
        currentUser: {},
      },
      action,
    ) {
      return {
        ...state,
        currentUser: {
          ...state.currentUser,
          list:list
        },
      };
    },
  },
};
export default AdminFileModel;


